﻿using System;
using Framework.MVC;
using Log.Model;
using Account.Model;
using Account.Model.Behavior;
using Framework.MVVM.Model;
using Account.IService;
using Account.Service;
using Common.IService;
using Log.IService;
using Common.Service;
using Log.Service;


namespace FrontCenter.Models
{
    [ServiceAttribute(typeof(IAccountService), typeof(AccountService), "Instance")]
    [ServiceAttribute(typeof(ILogService), typeof(LogService), "Instance")]
    [ServiceAttribute(typeof(ICodeService), typeof(CodeService), "Instance")]
    [ServiceAttribute(typeof(IAccountService), typeof(AccountService), "Instance")]
    public class ContainsAccountModel : AsyncModelBase, IWriteLog, IContainsAccount
    {
        #region Field

        private const string m_error_contains="consacct0";
        private const string m_complete_contains = "consacct1";

        private const char m_split=';';

        private const string m_result = "result";

        #endregion Field

        #region Property

        public string Source { get; set; }
        public string AccountResource { get; set; }

        #endregion Property

        #region AsyncModelBase

        protected override void OnInit(Type type)
        {
            OnBeginRequest();
            this.ContainsAccount(AccountResource, m_error_contains, m_complete_contains);
        }

        #endregion AsyncModelBase

        #region IWriteLog

        public void OnWriteLogComplete(string eventCode)
        {
            OnEndRequest();
        }

        public void OnWriteLogError(string eventCode)
        {
            OnEndRequest();
        }

        #endregion IWriteLog

        #region IContainsAccount

        public string AccountName { get; set; }

        public void OnContainsAccountComplete(string key, bool result)
        {
            OnComplete(m_result, result);
            this.Log(key, Source + m_split + AccountName);
        }

        public void OnContainsAccountError(string key)
        {
            this.Log(key, Source + m_split + AccountName);
        }

        #endregion IContainsAccount




        
    }
}